package com.lin.project.cloudnative.common;

/**
 * @description: 返回工具类
 * @author: linhuaixu
 * @time: 2023/5/15 15:06
 */
public class ResultUtils {
    /**
     *
     *
     * @description: 成功
     * @param data
     * @param <T>
     * @return:
     * @author: linhuaixu
     * @time: 2023/5/15 15:08
     */

    public static <T> BaseResponse<T> success(T data){
        return new BaseResponse<>(0,data,"ok");
    }

    /**
     *
     *
     * @description: 失败
     * @param errorCode
     * @return:
     * @author: linhuaixu
     * @time: 2023/5/15 15:10
     */

    public static BaseResponse error(ErrorCode errorCode){
        return new BaseResponse<>(errorCode);
    }

    /**
     *
     *
     * @description: 失败
     * @param code
     * @param message
     * @return:
     * @author: linhuaixu
     * @time: 2023/5/15 15:10
     */

    public static BaseResponse error(int code,String message){
        return new BaseResponse<>(code,null,message);
    }

    /**
     *
     *
     * @description: 失败
     * @param errorCode
     * @param message
     * @return:
     * @author: linhuaixu
     * @time: 2023/5/15 15:10
     */

    public static BaseResponse error(ErrorCode errorCode,String message){
        return new BaseResponse<>(errorCode.getCode(),null,message);
    }
}
